package com.upf1sh.controller;

import com.upf1sh.bean.GreenRover030001;
import com.upf1sh.service.GreenRover030001Service;
import com.upf1sh.utils.Result;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Description: 消毒机器人
 * @Title: GreenRoverController
 * @Package com.upf1sh.controller
 * @Author:
 * @CreateTime: 2024/9/19 21:00
 */
@CrossOrigin("*")
@RestController
@RequestMapping("/GreenRover")
public class GreenRoverController {

    @Resource
    private GreenRover030001Service greenRoverService;

//    @GetMapping("/list")
//    public Result getList(GreenRover030001 entity) {
//        List<GreenRover030001> list = greenRoverService.getList(entity);
//        return Result.ok().data("list",list);
//    }

    @GetMapping("/list")
    public Result getList(GreenRover030001 entity) {
        List<GreenRover030001> list = greenRoverService.getListWithLimit(entity, 100); // 限制返回100条记录
        return Result.ok().data("list", list);
    }

    @GetMapping(value = "/{id}")
    public Result getInfo(@PathVariable("id") Long id) {
        GreenRover030001 entity = greenRoverService.getById(id);
        return Result.ok().data("entity",entity);
    }

    @PostMapping("add")
    public Result add(@RequestBody GreenRover030001 entity) {
        greenRoverService.add(entity);
        return Result.ok();
    }

    @PostMapping("delete/{id}")
    public Result delete(@PathVariable("id") Long id) {
        GreenRover030001 entity  =  new GreenRover030001();
        entity.setId(id);
        greenRoverService.delete(entity);
       return Result.ok();
    }

    @PostMapping("update")
    public Result update(@RequestBody GreenRover030001 entity) {
        greenRoverService.update(entity);
        return Result.ok();
    }

    @GetMapping("/queryDeviceProperty")
    public Result queryDeviceProperty(@RequestParam("productId") String productId, @RequestParam("deviceName") String deviceName) {
        GreenRover030001 entity = new GreenRover030001();
        entity.setProductId(productId);
        entity.setDeviceName(deviceName);
        GreenRover030001 info = greenRoverService.getInfo(entity);
        return Result.ok().data("entity",info);
    }
}
